package com.shsun.curveservice.logic.service.impl;

import com.shsun.curveapi.domain.bo.TaskBO;
import com.shsun.curveapi.domain.dto.AddTaskDTO;
import com.shsun.curveservice.domain.entity.Task;
import com.shsun.curveservice.logic.async.TaskCalendarAsyncService;
import com.shsun.curveservice.logic.service.TaskService;
import com.shsun.curveservice.logic.service.TaskMgrService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * curve mgr service impl
 *
 * @author shsun
 * @date 2024/06/09
 */
@Service
public class TaskMgrServiceImpl implements TaskMgrService {
    @Resource
    private TaskService taskService;
    @Resource
    private TaskCalendarAsyncService taskCalendarAsyncService;

    @Override
    public void add(AddTaskDTO addTaskDTO) {
        Task task = new Task();
        task.setTaskName(addTaskDTO.getTaskName());
        task.setRuleId(addTaskDTO.getRuleId());
        task.setEndDate(addTaskDTO.getEndDate());
        taskService.save(task);
        TaskBO convert = AddTaskDTO.convert(addTaskDTO);
        convert.setTaskId(task.getId());
        // 生成日历
        taskCalendarAsyncService.generateTaskCalendar(convert);
    }
}
